import java.awt.BorderLayout;
import java.awt.Color;

import java.awt.EventQueue;

import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.AbstractButton;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JTextArea;
import javax.swing.JLabel;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JTextField;
import javax.swing.JRadioButton;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.util.Enumeration;

import javax.swing.JButton;


public class MainPlayerView extends JFrame {

	private MainPlayerModel mm;
	private JPanel contentPane;
	private JTextField mainPlayerName;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;
	private JButton nextButton;
	private JRadioButton hobo, mechanic, stockbroker;
	private ButtonGroup group;
	//private int index;

	/**
	 * Create the frame.
	 */
	public MainPlayerView(MainPlayerModel mm) 
	{
		this.mm = mm;
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(50, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setBackground(new Color(218, 165, 32));
		setContentPane(contentPane);
		
		JTextArea txtrthereHasBeen = new JTextArea();
		txtrthereHasBeen.setBackground(new Color(218, 165, 32));
		txtrthereHasBeen.setFont(new Font("Tahoma", Font.BOLD, 12));
		txtrthereHasBeen.setText("\"There has been a TV newscast that just announced that there will be a zombie apocalypse and that everyone needs to get to safety. The only area that is safe is in Russia.\"");
		txtrthereHasBeen.setLineWrap(true);
		
		JLabel lblNewLabel = new JLabel("Leader Name");
		lblNewLabel.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 12));
		
		mainPlayerName = new JTextField();
		mainPlayerName.setColumns(10);
		
		JLabel lblProfession = new JLabel("Profession");
		lblProfession.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 12));
		
		hobo = new JRadioButton("Hobo");
		hobo.setBackground(new Color(218, 165, 32));
		
		mechanic = new JRadioButton("Mechanic");
		mechanic.setBackground(new Color(218, 165, 32));
		
		stockbroker = new JRadioButton("Stock Broker");
		stockbroker.setBackground(new Color(218, 165, 32));
		
		group = new ButtonGroup();
	    group.add(hobo);
	    group.add(mechanic);
	    group.add(stockbroker);
	    
	    
	   
		JLabel lblNewLabel_1 = new JLabel("Passengers");
		lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 12));
		
		textField_1 = new JTextField();
		textField_1.setColumns(10);
		
		textField_2 = new JTextField();
		textField_2.setColumns(10);
		
		textField_3 = new JTextField();
		textField_3.setColumns(10);
		
		textField_4 = new JTextField();
		textField_4.setColumns(10);
		
		JTextArea txtrHasTheLeast = new JTextArea();
		txtrHasTheLeast.setBackground(new Color(218, 165, 32));
		txtrHasTheLeast.setFont(new Font("Tahoma", Font.PLAIN, 11));
		txtrHasTheLeast.setText("has no money, but has the best skills to gather food ");
		
		nextButton = new JButton("Next->");
		
		JTextArea txtrHasMediumAmount = new JTextArea();
		txtrHasMediumAmount.setBackground(new Color(218, 165, 32));
		txtrHasMediumAmount.setFont(new Font("Tahoma", Font.PLAIN, 11));
		txtrHasMediumAmount.setText("has medium amount of cash but is the best at repairing parts. ");
		
		JTextArea txtrHasTheMost = new JTextArea();
		txtrHasTheMost.setBackground(new Color(218, 165, 32));
		txtrHasTheMost.setFont(new Font("Tahoma", Font.PLAIN, 11));
		txtrHasTheMost.setText("has the most money but doesn't have any other abilities\r\n");
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addComponent(txtrthereHasBeen, GroupLayout.PREFERRED_SIZE, 432, GroupLayout.PREFERRED_SIZE)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addComponent(lblNewLabel)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(mainPlayerName, GroupLayout.PREFERRED_SIZE, 193, GroupLayout.PREFERRED_SIZE))
						.addComponent(lblProfession)
						.addComponent(lblNewLabel_1)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addContainerGap()
							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_contentPane.createSequentialGroup()
									.addComponent(stockbroker)
									.addGap(18)
									.addComponent(txtrHasTheMost, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
								.addGroup(gl_contentPane.createSequentialGroup()
									.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
										.addComponent(textField_3)
										.addComponent(textField_1, GroupLayout.DEFAULT_SIZE, 151, Short.MAX_VALUE))
									.addPreferredGap(ComponentPlacement.RELATED)
									.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
										.addComponent(textField_2)
										.addComponent(textField_4, GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE))
									.addGap(18)
									.addComponent(nextButton))
								.addGroup(gl_contentPane.createSequentialGroup()
									.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
										.addComponent(hobo)
										.addComponent(mechanic))
									.addGap(34)
									.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
										.addComponent(txtrHasTheLeast)
										.addComponent(txtrHasMediumAmount))))
							.addGap(68)))
					.addContainerGap())
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addComponent(txtrthereHasBeen, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel)
						.addComponent(mainPlayerName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(lblProfession)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addComponent(hobo)
						.addComponent(txtrHasTheLeast, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(mechanic)
						.addComponent(txtrHasMediumAmount, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(stockbroker)
						.addComponent(txtrHasTheMost, GroupLayout.PREFERRED_SIZE, 21, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addComponent(lblNewLabel_1)
							.addGap(12)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
								.addComponent(textField_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(textField_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
							.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
								.addComponent(textField_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(textField_4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addComponent(nextButton)
							.addContainerGap())))
		);
		contentPane.setLayout(gl_contentPane);
	}
	
	public void addNextButtonListener(ActionListener al)
	{
		nextButton.addActionListener(al);
	}
	
	public String getMainPlayerName()
	{
		return mainPlayerName.getText();
	}
	
	public String[] getPartyMembersNames()
	{
		String[] partyMembersNames = new String[mm.getMaxNumPartyMembers()];
		partyMembersNames[0] = textField_1.getText();
		partyMembersNames[1] = textField_2.getText();
		partyMembersNames[2] = textField_3.getText();
		partyMembersNames[3] = textField_4.getText();
		
		return partyMembersNames;
	}
	
	public int getProfessionIndex() 
	{
		int index = 0;
		if(hobo.isSelected()){
			index= 0;
		}
		if(mechanic.isSelected()){
			index = 1;
		}
		if(stockbroker.isSelected()){
			index = 2;
		}
		return index;
//		int i = 0;
//	    for (Enumeration<AbstractButton> e = group.getElements(); e.hasMoreElements();) 
//	    {
//	    	JRadioButton b = (JRadioButton) e.nextElement();
//	    	if (b.getModel() == group.getSelection()) 
//	    		return i;
//	    	i++;
//	    }
//	    return -1;
	}
	
}